var vote= new Vue({
    el : '#Votelist',
    data:{
        userId : $("#id").val(),
        xiangmuId:$("#xiangmuId").val(),
        xiangmuleixing:$("#xiangmuleixing").val(),
        lunci:$("#lunci").val(),

        usernum:'',
        drugname:'',
        jicaiyao:'',
        jiyao:'',

        xiangmu : {},
        votelist:[],
        show : false,
        total:0,
        tongyishu:0,
        butongyishu:0,


        qiyepass:'',
        jicaipass:'',
        jicaishengyu:'',

        issubmited:false,
        isallsubmited:false,


        pageIndex : 1,
        pageSize :9999,
        pageCount : 0,
        recordCount : 0,
        inputPageIndexValue : "",
    },
    created : function() {
        $.ajaxSettings.async = false;
        var _this = this;
        $(".nav navbar-nav li").removeClass("active");
        $("#nav_biaojue").addClass("active");
        _this.findIsacticed();
    },
    methods : {

        findIsacticed:function (){
            var _this = this;
            layer.open({type:3});
            $.post('/xiangmu/find_one', {
                xianmguid :_this.xiangmuId,
                rdm : Math.random()
            },function(ppData) {
                layer.closeAll("loading");
                if(ppData != null){
                    if(ppData.result == "1"){
                        var data = ppData.resultContent;
                        _this.xiangmu = data;
                        _this.xiangmuId=_this.xiangmu.xiangmuid;
                        _this.xiangmuleixing=_this.xiangmu.xiangmuleixing;
                        _this.usernum = data.zhuangjiashu;
                        _this.checkIsSubmited();
                        _this.checkIsAllSubmited();
                        _this.getResultCount();

                    }else{
                        layer.alert(ppData.message);
                    }
                }
            },"json");
        },

        remove:function (){
           this.guigexuhao="";
           this.drugname="";
           this.jicaiyao="";
           this.jiyao="";
           this.findBiaojuelist();
        },

        toRefresh:function (){
            location.reload();
        },

        findBiaojuelist:function (){
            var _this = this;
            layer.open({type:3});
            $.post("/fujianbjieguo/findBiaojuelist",{
                xiangmuid :_this.xiangmuId,
                xiangmuleixing :_this.xiangmuleixing,
                userid :_this.userId,
                drugname:_this.drugname,
                pageindex : _this.pageIndex,
                pagesize : _this.pageSize,
                rdm : Math.random()
            },function(ppData){
                layer.closeAll("loading");
                if (ppData != null){
                    if(ppData.result == "1"){
                        var data=ppData.resultContent;
                        var mmHtml = _this.createHtml(data,_this.xiangmuleixing)
                        $("#List").html(mmHtml);
                    }else{
                        layer.alert(ppData.message);
                    }
                }

            },"json");
        },
        createHtml:function (data,xiangmuLeixing) {
            var _this = this
            if(xiangmuLeixing=="35"){
                var mmHtml = "<div class='table-head'><table class=\"table table-hover table-bordered\" style=\"overflow:hidden; margin-bottom:0px;table-layout:fixed;\" v-if=\"show\" cellspacing=\"0\" cellpadding=\"0\">\n" +
                    "   <thead >\n" +
                    "    <tr style=\"font-weight: bold;\">\n" +
                    "        <td style=\"text-align:center;vertical-align:middle;width:50px;\" rowspan=\"2\">序号</td>\n" +
                    "        <td style=\"text-align:center;vertical-align:middle;width:200px;\" rowspan=\"2\" >药品名称</td>\n" +
                    "        <td style=\"text-align:center;vertical-align:middle;width:200px;\" rowspan=\"2\" >规格</td>\n" +
                    "        <td style=\"text-align:center;vertical-align:middle;width:120px;\" rowspan=\"2\" >是否为新增品种</td>\n" +
                    "        <td style=\"text-align:center;vertical-align:middle;width:120px;\" rowspan=\"2\" >有无临床需求</td>\n" +
                    "        <td style=\"text-align:center;vertical-align:middle;width:100px;\" rowspan=\"2\" >申请科室</td>\n" +
                    "        <td style=\"text-align:center;vertical-align:middle;width:150px;\" rowspan=\"2\" >有无同功效品种</td>\n" +
                    "        <td style=\"text-align:center;vertical-align:middle;width:100px;\" rowspan=\"2\" >预选会意见</td>\n" +
                    "        <td style=\"text-align:center;vertical-align:middle;width:100px;\" rowspan=\"2\" >备注</td>\n" +
                    "        <td style=\"text-align:center;vertical-align:middle;\">表决意见（同意保留请打勾）</td>\n" +
                    "    </tr>\n" +
                    "    </thead></table></div><div class='table-body'><table style=\"table-layout: fixed;\"><tbody>";

                if(data.ShengchanList.length > 0){
                    _this.show = true;
                    _this.Shengchanqiyelist=data.ShengchanList;

                    var PageInfo = data.PageInfo;
                    _this.pageIndex = PageInfo.pageIndex;
                    _this.recordCount = PageInfo.recordCount;
                    _this.pageCount = PageInfo.pageCount;

                    for (var i = 0; i < data.ShengchanList.length; i++) {
                        var mmShengchan = data.ShengchanList[i];

                        var mmPinzhongxuhao=parseInt(mmShengchan.xuhao);
                        var mmYaopinmingcheng=mmShengchan.yaopinmingcheng;

                        var mmPinguiList = mmShengchan.pinguilist;
                        var mmPinzhongHebingshu = mmShengchan.pinzhonghebinghang;

                        for (var j = 0; j < mmPinguiList.length; j++) {
                            var s=0;

                            var mmPinguilist = mmPinguiList[j];

                            var mmPinguixuhao = parseInt(mmPinguilist.beuzhu1);
                            var mmYaopinmingcheng = mmPinguilist.yaopinmingcheng;
                            var mmGuige = mmPinguilist.guige;
                            var mmShifouxinzengpinzhong = mmPinguilist.shifouxinzengpinzhong;
                            var mmYouwulinchuangxuqiu = mmPinguilist.youwulinchuangxuqiu;
                            var mmShenqingkeshi = mmPinguilist.shenqingkeshi;
                            var mmYouwutonggongxiao = mmPinguilist.youwutonggongxiao;
                            var mmYuxuanyijian = mmPinguilist.yuxuanhuiyijian;
                            var mmBeizhu = mmPinguilist.beizhu;
                            var mmResult = mmPinguilist.result;

                            var mmPinguiHebingshu = mmPinguilist.pinguihebinghang;

                            var mmHuanhangfu = "";
                            var mmerjihe="";
                            if (j != 0) {
                                mmHuanhangfu = "<tr>";
                            }else {
                                if(mmYouwutonggongxiao=="有"){
                                    mmerjihe += "<td style='text-align:center;vertical-align:middle;width: 50px;background:lightgreen;height: 100%'  rowspan='" + mmPinzhongHebingshu + "'>" + mmPinzhongxuhao + "</td>";
                                    mmerjihe += "<td style='text-align:center;vertical-align:middle;width: 200px;background:lightgreen;'  rowspan='" + mmPinzhongHebingshu + "'>" + mmYaopinmingcheng + "</td>";

                                }else{
                                    mmerjihe += "<td style='text-align:center;vertical-align:middle;width: 50px;height: 100%'  rowspan='" + mmPinzhongHebingshu + "'>" + mmPinzhongxuhao + "</td>";
                                    mmerjihe += "<td style='text-align:center;vertical-align:middle;width: 200px;'  rowspan='" + mmPinzhongHebingshu + "'>" + mmYaopinmingcheng + "</td>";
                                }

                            }
                            mmHtml +=mmerjihe;

                            var mmBtndiv="";
                            if(_this.issubmited){
                                if(mmResult==null||mmResult==0){
                                    mmBtndiv="<div id='div_"+mmPinguixuhao+"' style=\"text-align:center;\"><input style=\"width: 30px;height: 30px;\" disabled onclick=\"toVote('"+mmPinzhongxuhao+"','"+mmPinguixuhao+"')\" id='checkbox_"+mmPinguixuhao+"' class='cbcss' type=\"checkbox\"></div>";
                                }
                                if(mmResult==1){
                                    mmBtndiv="<div id='div_"+mmPinguixuhao+"' style=\"text-align:center;\"><input style=\"width: 30px;height: 30px;\" disabled checked onclick=\"toVote('"+mmPinzhongxuhao+"','"+mmPinguixuhao+"')\" id='checkbox_"+mmPinguixuhao+"' class='cbcss' type=\"checkbox\"></div>";
                                }
                            }
                            if(!_this.issubmited) {
                                if(mmResult==null||mmResult==0){
                                    mmBtndiv="<div id='div_"+mmPinguixuhao+"' style=\"text-align:center;\"><input style=\"width: 30px;height: 30px;\" onclick=\"toVote('"+mmPinzhongxuhao+"','"+mmPinguixuhao+"')\" id='checkbox_"+mmPinguixuhao+"' class='cbcss' type=\"checkbox\"></div>";
                                }
                                if(mmResult==1){
                                    mmBtndiv="<div id='div_"+mmPinguixuhao+"' style=\"text-align:center;\"><input style=\"width: 30px;height: 30px;\" checked onclick=\"toVote('"+mmPinzhongxuhao+"','"+mmPinguixuhao+"')\" id='checkbox_"+mmPinguixuhao+"'  class='cbcss' type=\"checkbox\"></div>";
                                }
                            }

                            if(mmYouwutonggongxiao=="有"){
                                mmHtml += "<td style='text-align:center;vertical-align:middle;width: 200px;background:lightgreen;white-space:nowrap;text-overflow: ellipsis; overflow: hidden;'  rowspan='" + mmPinguiHebingshu + "'><a title='" + mmGuige + "'>" + mmGuige + "</a></td>";
                                mmHtml += "<td style='text-align:center;vertical-align:middle;width: 120px;background:lightgreen;'><div id='div_" + mmPinguixuhao + "_shifouxinzengpinzhong' style=\"text-align:center;\">" + mmShifouxinzengpinzhong + "</div></td>";
                                mmHtml += "<td style='text-align:center;vertical-align:middle;width: 120px;background:lightgreen;'><div id='div_" + mmPinguixuhao + "_youwulinchuangxuqiu' style=\"text-align:center;\">" + mmYouwulinchuangxuqiu + "</div></td>";
                                mmHtml += "<td style='text-align:center;vertical-align:middle;width: 100px;background:lightgreen;'><div id='div_" + mmPinguixuhao + "_shenqingkeshi' style=\"text-align:center;\">" + mmShenqingkeshi + "</div></td>";
                                mmHtml += "<td style='text-align:center;vertical-align:middle;width: 150px;background:lightgreen;'><div id='div_" + mmPinguixuhao + "_youwutonggongxiao' style=\"text-align:center;\">" + mmYouwutonggongxiao + "</div></td>";
                                mmHtml += "<td style='text-align:center;vertical-align:middle;width: 100px;background:lightgreen;'><div id='div_" + mmPinguixuhao + "_yuxuanyijian' style=\"text-align:center;\">" + mmYuxuanyijian + "</div></td>";
                                mmHtml += "<td style='text-align:center;vertical-align:middle;width: 100px;background:lightgreen;'><div id='div_" + mmPinguixuhao + "_beizhu' style=\"text-align:center;\">" + mmBeizhu + "</div></td>";
                                mmHtml += "<td style='text-align:center;vertical-align:middle;background:lightgreen;'>" + mmBtndiv + "</td>";

                            }else{

                                mmHtml += "<td style='text-align:center;vertical-align:middle;width: 200px;white-space:nowrap;text-overflow: ellipsis; overflow: hidden;'  rowspan='" + mmPinguiHebingshu + "'><a title='" + mmGuige + "'>" + mmGuige + "</a></td>";
                                mmHtml += "<td style='text-align:center;vertical-align:middle;width: 120px;'><div id='div_" + mmPinguixuhao + "_shifouxinzengpinzhong' style=\"text-align:center;\">" + mmShifouxinzengpinzhong + "</div></td>";
                                mmHtml += "<td style='text-align:center;vertical-align:middle;width: 120px;'><div id='div_" + mmPinguixuhao + "_youwulinchuangxuqiu' style=\"text-align:center;\">" + mmYouwulinchuangxuqiu + "</div></td>";
                                mmHtml += "<td style='text-align:center;vertical-align:middle;width: 100px;'><div id='div_" + mmPinguixuhao + "_shenqingkeshi' style=\"text-align:center;\">" + mmShenqingkeshi + "</div></td>";
                                mmHtml += "<td style='text-align:center;vertical-align:middle;width: 150px;'><div id='div_" + mmPinguixuhao + "_youwutonggongxiao' style=\"text-align:center;\">" + mmYouwutonggongxiao + "</div></td>";
                                mmHtml += "<td style='text-align:center;vertical-align:middle;width: 100px;'><div id='div_" + mmPinguixuhao + "_yuxuanyijian' style=\"text-align:center;\">" + mmYuxuanyijian + "</div></td>";
                                mmHtml += "<td style='text-align:center;vertical-align:middle;width: 100px;'><div id='div_" + mmPinguixuhao + "_beizhu' style=\"text-align:center;\">" + mmBeizhu + "</div></td>";
                                mmHtml += "<td style='text-align:center;vertical-align:middle;'>" + mmBtndiv + "</td>";

                            }

                            mmHtml += "</tr>";
                        }
                    }
                }else {
                    _this.show = false;
                }
                return mmHtml += "</tbody></table>";

            }
        },

        getResultCount:function (){
            var _this = this;
            layer.open({type:3});
            $.post('/fujianbjieguo/getResultCount', {
                xiangmuid :_this.xiangmuId,
                xiangmuleixing :_this.xiangmuleixing,
                userid :_this.userId,
                rdm : Math.random()
            },function(ppData) {
                layer.closeAll("loading");
                if(ppData != null){
                    if(ppData.result == "1"){
                        var data = ppData.resultContent;
                        _this.qiyepass=data.qiyepass;
                    }else{
                        layer.alert(ppData.message);
                    }
                }
            },"json");
        },

        checkIsSubmited:function (){
            var _this = this;
            layer.open({type:3});
            $.post('/renyuanfenpei/checkIsSubmited', {
                xiangmuid :_this.xiangmuId,
                userid :_this.userId,
                rdm : Math.random()
            },function(ppData) {
                layer.closeAll("loading");
                if(ppData != null){
                    if(ppData.result == "1"){
                        if(ppData.resultContent=="1"){
                            _this.issubmited=true;
                        }
                        _this.findBiaojuelist();
                    }else{
                        layer.alert(ppData.message);
                    }
                }
            },"json");
        },

        checkIsAllSubmited:function (){
            var _this = this;
            layer.open({type:3});
            $.post('/renyuanfenpei/checkIsAllSubmited', {
                xiangmuid :_this.xiangmuId,
                userid :_this.userId,
                rdm : Math.random()
            },function(ppData) {
                layer.closeAll("loading");
                if(ppData != null){
                    if(ppData.result == "1"){
                        if(ppData.resultContent=="1"){
                            _this.isallsubmited=true;
                        }
                    }else{
                        layer.alert(ppData.message);
                    }
                }
            },"json");
        },

        voteAll:function(){
            var _this = this;
            layer.open({type: 3});
            $.post('/fujianjieguo/voteAll', {
                xiangmuid :_this.xiangmuId,
                xiangmuleixing :_this.xiangmuleixing,
                userid :_this.userId,
                rdm: Math.random()
            }, function (ppData) {
                layer.closeAll("loading");
                if (ppData != null) {
                    if (ppData.result == "1") {
                        layer.alert("表决成功");
                        location.reload()
                    } else {
                        layer.alert(ppData.message);
                    }
                }
            }, "json");
        },

        tosubmit:function (){
            var _this = this;
            layer.confirm("是否确认提交？",{
                btn : ['是','否']
            },function(){
                layer.open({type:3});
                $.post('/fujianjieguo/submit', {
                    xiangmuid :_this.xiangmuId,
                    xiangmuleixing :_this.xiangmuleixing,
                    userid :_this.userId,
                    rdm : Math.random()
                },function(ppData) {
                    layer.closeAll("loading");
                    if(ppData != null){
                        if(ppData.result == "1"){
                            _this.issubmited=true;
                            layer.alert("提交成功");
                            _this.findBiaojuelist();

                            setTimeout(function(){
                                _this.checkIsAllSubmited();
                            },5000);

                        }else{
                            layer.alert(ppData.message);
                        }
                    }
                },"json");
            })
        },

        //跳到首页
        SetPageIndex : function(){
            this.pageIndex = 1;
        },
        SetPageEnd : function(){
            this.pageIndex = this.pageCount;
        },
        //上一页
        SetPageIndexPrePage : function(){
            var PrePage = ((this.pageIndex -1) <= 0) ? 1 : (this.pageIndex -1);
            this.pageIndex = PrePage;
        },
        //下一页
        SetPageIndexNextPage : function(){
            var NextPage = ((this.pageIndex +1) >= this.pageCount) ? this.pageCount : (this.pageIndex +1);
            this.pageIndex = NextPage;
        },
        //跳转界面
        JumpPage : function(){
            if(this.inputPageIndexValue <= 1){
                this.inputPageIndexValue = 1;
            }else if(this.inputPageIndexValue >= this.pageCount){
                this.inputPageIndexValue = this.pageCount;
            }
            this.pageIndex = this.inputPageIndexValue;
            this.inputPageIndexValue = '';
        },
    },
    watch :{

        //监控分页情况，刷新列表
        pageIndex : function(){
            this.findBiaojuelist();
        }

    }
})